package com.whxyxj.text3;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.List;
import java.util.Map;


public class ZtkSimpleAdapter extends SimpleAdapter{

    Context context;

    public ZtkSimpleAdapter(Context context, List<? extends Map<String, ?>> data,
                            int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);
        this.context = context;
        // TODO Auto-generated constructor stub
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View v = super.getView(position, convertView, parent);

        final Button tz=(Button) v.findViewById(R.id.bt_ztt);
        final Button qd=(Button) v.findViewById(R.id.bt_ztq);
        final int p = position;
        String no=null;
        final String ac =null;
        switch (p) {
               case 0:
                   no="001";
                   break;
               case 1:
                   no="010";
                   break;
               case 2:
                   no="011";
                   break;
               case 3:
                    no="100";
                    break;
               case 4:
                    no="101";
                    break;
               case 5:
                    no="110";
                    break;
                case 6:
                    no="111";
                     break;
            default:
                     break;
                }
        final String finalNo = no;
        Log.d("Position", Integer.toString(position));
        tz.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String act ="01";
                String acb= finalNo +act;
                qd.setText("启动");
                Toast.makeText(context, "指令为"+acb,Toast.LENGTH_LONG).show();
            }
        });

        qd.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String act ="10";
                String acb= finalNo +act;
                qd.setText("已启动");
                // TODO Auto-generated method stub
                Toast.makeText(context, "指令为"+acb,Toast.LENGTH_LONG).show();
            }
        });

        return v;
    }

}